@layout("/common/lyy/_container.html"){
 <div data-options="region:'north',border:false,collapsible:false,minHeight:30" style="display:none;"  id="clientContainer">
    	 <div id="toolbar" style="display: none;">
    	 		@if(shiro.hasPermission("/erpkind/add")){
                <a onclick="openAddClient();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">添加</a>
         		@}
                </div>
        <!-- <div style="margin-top: 4px">
        <input id="searchKey" name="searchKey" '> <input id="searchWord"
                name="searchWord" '>
         <label style="margin-left: 20px;">是否正常：</label><input
                id="ifUse" name="ifUse">
        </div>
         -->
    </div>
    <div data-options="region:'center',border:false,">
        <div id="mainDatagrid"></div>
    </div>
    <div id="viewWindow_orgProductSku" style="padding: 10px 20px;display:none;"></div>
    <div id="addDialog" style="padding: 10px 20px;display:none;">
        <div style="margin-bottom: 5px;">连锁客户信息</div>
        <form id="addForm" method="post">
            <table>
            	<tr>
                    <td align="right"><label>主键:</label></td>
                    <td><input id="id"  name="id" ></td>
                </tr>
                <tr>
                    <td align="right"><label>账套标识:</label></td>
                    <td><input id="accountId"  name="accountId" ></td>
                </tr>
                <tr>
                    <td align="right"><label>账套名称:</label></td>
                    <td><input id="accountName"  name="accountName" ></td>
                </tr>
                <tr>
                    <td align="right"><label>账套描述:</label></td>
                    <td><input  id="accountDesc" name="accountDesc"></td>
                </tr>
                <tr>
                    <td align="right"><label>账套前缀:</label></td>
                    <td><input  id="accountPrefix" name="accountPrefix"></td>
                </tr>
                <tr>
                    <td align="right"><label>账套后缀:</label></td>
                    <td><input  id="accountSuffix" name="accountSuffix"></td>
                </tr>
                <tr>
			        <td style="text-align:right;">是否主账套：</td>
			        <td style="text-align:left">
			            <span class="radioSpan">
			                <input type="radio" name="ifMain" value="1">主账套</input>
			                <input type="radio" name="ifMain" value="0">非主账套</input>
			            </span>
			        </td>
			    </tr>
                <tr>
                    <td align="right"><label>绑定的数据源:</label></td>
                    <td><input  id="dataSource" name="dataSource"></td>
                </tr>
                 
            </table>
        </form>
    </div>
    <div id="editDialog" style="padding: 10px 20px;display:none; ">
        <div style="margin-bottom: 5px;">连锁客户信息</div>
        <form id="editForm" method="post">
           <table>
            	<tr>
                    <td align="right"><label>主键:</label></td>
                    <td><input id="id"  name="id" ></td>
                </tr>
                <tr>
                    <td align="right"><label>账套标识:</label></td>
                    <td><input id="accountId"  name="accountId" ></td>
                </tr>
                <tr>
                    <td align="right"><label>账套名称:</label></td>
                    <td><input id="accountName"  name="accountName" ></td>
                </tr>
                <tr>
                    <td align="right"><label>账套描述:</label></td>
                    <td><input  id="accountDesc" name="accountDesc"></td>
                </tr>
                 <tr>
                    <td align="right"><label>账套前缀:</label></td>
                    <td><input  id="accountPrefix" name="accountPrefix"></td>
                </tr>
                <tr>
                    <td align="right"><label>账套后缀:</label></td>
                    <td><input  id="accountSuffix" name="accountSuffix"></td>
                </tr>
                
                 <tr>
			        <td style="text-align:right;">是否主账套：</td>
			        <td style="text-align:left">
			            <span class="radioSpan">
			                <input type="radio" name="ifMain" value="1">主账套</input>
			                <input type="radio" name="ifMain" value="0">非主账套</input>
			            </span>
			        </td>
			    </tr>
                
                
                <tr>
                    <td align="right"><label>绑定的数据源:</label></td>
                    <td><input  id="dataSource" name="dataSource"></td>
                </tr>
            </table>
        </form>
    </div>
    
<script type="text/javascript">

	var searchKey;
	var searchWord;
	var ifUse;

	$(function() {
		$("#addDialog,#editDialog,#viewWindow_orgProductSku,#clientContainer").show();
		searchKey = $('#searchKey').val();
		searchWord = $('#searchWord').val();

		$('#mainDatagrid')
				.datagrid(
						{
							url : Feng.ctxPath + "/erpkind/list",
							queryParams : {
								searchKey : searchKey,
								searchWord : searchWord,
								ifUse :ifUse
							},
							pagination : true,
							rownumbers : true,
							fit : true,
							fitColumns : true,
							singleSelect : true,
							border : true,
							remoteSort : false,
							pageSize : 20,
							columns : [ [ {
								field : 'id',
								title : '编号',
								sortable : true
							}, {
								field : 'accountId',
								title : '账套标识',
								sortable : true
							}, {
								field : 'accountName',
								title : '账套名称',
								sortable : true
							}, {
								field : 'accountDesc',
								title : '账套描述'
							}, {
								field : 'accountPrefix',
								title : '账套前缀',
								sortable : true
							}, {
								field : 'accountSuffix',
								title : '账套后缀',
								sortable : true
							},
							 {
									field : 'ifMain',
									title : '是否主账套',
									sortable : true,
									formatter : function(value, row, index) {
										if (row.ifMain != null) {
											switch (row.ifMain) {
											case "1":
												return "主账套";
												break;
											case "0":
												return "非主账套";
												break;
											
											}
										}
									}
								}
							
							
							
							, {
								field : 'dataSource',
								title : '绑定的数据源',
								sortable : true
							},
							{
								field : 'action',
								title : '操作',
								width : 120,
								formatter : function(value, row, index) {
									var str = '&nbsp;';
									@if(shiro.hasPermission("/erpkind/update")){
									str += $.formatString(
													'<a href="javascript:void(0)"   class="edit">编辑</a>',
													row.resourceId);
									str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
									@}
									@if(shiro.hasPermission("/erpkind/delete")){
									str += $.formatString(
													'<a href="javascript:void(0)"   class="del">删除</a>',
													row.resourceId);
									@}
									return str;
								}
							}] ],
							toolbar :'#toolbar'
						});

        
		
		$('#addDialog')
		.dialog(
				{
					title : '添加连锁客户',
					width : '320px',
					height : '360px',
					closed : true,
					cache : false,
					modal : true,
					buttons : [
							{
								text : '保存',
								iconCls : 'icon-save',
								handler : function() {
									var formData   = $.serializeObject($('#addForm'));    
									//applyData=JSON.parse(normalMsg);
				  					//oldDate=JSON.stringify(applyData);
				  					console.log(JSON.stringify(formData))
									if (!formData.accountId
											|| !formData.accountName
											|| !formData.dataSource) {
										Feng.error("所有字段不能为空！");
									} else {
										
										var ajax = new $ax(Feng.ctxPath + "/erpkind/add", function (result) {
								            Feng.success("添加成功!");
															$(
																	'#addDialog')
																	.dialog(
																			'close');
								            reloadMainDataGrid();
								        }, function (data) {
								            Feng.error("添加失败!" + data.responseJSON.message + "!");
								        });
								        ajax.set(formData);
								        ajax.start();
										
										
										}
								}
							}, {
								text : '取消',
								iconCls : 'icon-cancel',
								handler : function() {
									$('#addDialog').dialog('close');
								}
							} ]
				});
		
		
		
		$('#editDialog')
		.dialog(
				{
					title : '修改连锁客户',
					width : '320px',
					height : '360px',
					closed : true,
					cache : false,
					modal : true,
					buttons : [
							{
								text : '保存',
								iconCls : 'icon-save',
								handler : function() {
									var formData   = $.serializeObject($('#editForm'));    
									//applyData=JSON.parse(normalMsg);
				  					//oldDate=JSON.stringify(applyData);
				  					console.log(JSON.stringify(formData))
									if (!formData.accountId
											|| !formData.accountName
											|| !formData.dataSource) {
										Feng.error("所有字段不能为空！");
									} else {
										
										var ajax = new $ax(Feng.ctxPath + "/erpkind/update", function (result) {
								            Feng.success("修改成功!");
															$(
																	'#editDialog')
																	.dialog(
																			'close');
								            reloadMainDataGrid();
								        }, function (data) {
								            Feng.error("修改失败!" + data.responseJSON.message + "!");
								        });
								        ajax.set(formData);
								        ajax.start();
										
										
										}
								}
							}, {
								text : '取消',
								iconCls : 'icon-cancel',
								handler : function() {
									$('#editDialog').dialog('close');
								}
							} ]
				});
		

		$('#ifUse').combobox({
			valueField : 'id',
			textField : 'title',
			editable : false,
			value : '',
			width : 80,
			data : [ {
				title : '空',
				id : ''
			}, {
				title : '正常',
				id : '1'
			}, {
				title : '停用',
				id : '0'
			} ],
			onChange : function(newValue, oldValue) {
				ifUse = $('#ifUse').combobox('getValue');
				reloadMainDataGrid();
			}
		});
		
		$('#searchKey').combobox({
			valueField : 'id',
			textField : 'title',
			editable : false,
			value : 'clientName',
			width : 120,
			data : [ {
				title : '客户端id',
				id : 'clientId'
			}, {
				title : '连锁客户名称',
				id : 'clientName'
			} ],
			onSelect : function(record) {
				searchKey = $('#searchKey').combobox('getValue');
			}
		});
		$('#searchWord').textbox({
			buttonText : '查找',
			iconCls : 'icon-search',
			iconAlign : 'right',
			onClickButton : function() {
				reloadMainDataGrid();
			},
			onChange : function(newValue, oldValue) {
				searchKey = $('#searchKey').combobox('getValue');
				searchWord = $('#searchWord').textbox('getValue');
			}
		});

	});
	
	
	
	
	
	//事件委托
	$(document).on("click",".edit",function(){
		var row = $('#mainDatagrid')
		.datagrid('getSelected');

		if (row) {
			$('#editDialog').dialog('open');
			$('#editForm').form('clear');
		
			$('#editForm')
					.form(
							'load',
							{
								id : row.id,
								accountId : row.accountId,
								accountName : row.accountName,
								accountDesc : row.accountDesc,
								accountPrefix : row.accountPrefix,
								accountSuffix : row.accountSuffix,
								ifMain : row.ifMain,
								dataSource : row.dataSource
							});
		} else {
			$.messager.show({
				title : '警告',
				msg : '请先选择一条记录!'
			});
		}
	        
	})
	$(document).on("click",".del",function(){
		var row = $('#mainDatagrid')
		.datagrid('getSelected');
		//console.log(row)
		//alert(row.id)
		
		 var ajax = new $ax(Feng.ctxPath + "/erpkind/delete", function (data) {
	            Feng.success("删除成功!");
	            reloadMainDataGrid();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("erpkindId",row.id);
	        ajax.start();
	        
	})
	
	
	
	
	function reloadMainDataGrid() {
		$('#mainDatagrid').datagrid("load", {
			searchKey : searchKey,
			searchWord : searchWord,
			ifUse : ifUse
		});
	}
	
	function openAddClient(){
		$('#addDialog').dialog('open');
		$('#addForm').form('clear');
		
	}
	
</script>
<script src="${ctxPath}/static/modular/ry600/client/client.js"></script>
@}